/*Diego Lima de Freitas RA: 317632
 *Yuri Souza Padua RA: 317420
 * 
 * Classe que trata as chamadas de procedimentos
 */
package AST;

public class ProcedureCall extends Command {

    private Procedure procedure;
    private ExprList exprList;

    public ProcedureCall(Procedure procedure, ExprList exprList) {
        this.procedure = procedure;
        this.exprList = exprList;
    }

    @Override
    public void genC(PW pw) {
        VarDec getInt = new VarDec("_getIntegerVar", Type.integerType);
                
        for(int i = 0; i<exprList.getParamList().size();i++){
            if( exprList.getParamList().get(i) instanceof GetIntegerExpr){

                pw.out.print("   int "+getInt.getName() + ";\n");
                pw.out.print("   scanf("+"\"%d\""+ ", "+"&"+getInt.getName()+");\n");
            }
        }
        pw.print(procedure.getName() + "(");
        if (exprList != null) {
            exprList.genC(pw);
            for(int i = 0; i<exprList.getParamList().size();i++){
                if( exprList.getParamList().get(i) instanceof GetIntegerExpr){
                    pw.out.print("_getIntegerVar");
                }
            }
        }
        
        pw.out.println(");");
    }
}
